{include file="public/base"}
<style>
    td,th{text-align: center}
</style>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>公告管理</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form action="">
                        <div class="row">
                            <div class="col-sm-5 m-b-xs" >
                                <a href="javascript:;" onclick="edit('')" class="btn btn-outline btn-info">添加公告</a>
                                <a href="javascript:;" onclick="DelAll()" class="btn btn-outline btn-danger">批量删除</a>
                            </div>
                        </div>
                    </form>
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th><input type="checkbox" class="i-checks" name="input" onclick="yanzheng(this,'checkbox[]')"></th>
                                <th>id</th>
                                <th>标题</th>
                                <th>公告</th>
                                <th>添加时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {foreach name="list" id="val"}
                            <tr>
                                <td>
                                    <input type="checkbox" class="i-checks" name="checkbox[]" value="{$val['id']}">
                                </td>
                                <td>{$val['id']}</td>
                                <td>{$val['title']}</td>
                                <td>{$val['content']}</td>
                                <td>{$val['createtime']|date="Y-m-d H:i:s",###}</td>
                                <td><a href="javascript:;" onclick="edit({$val['id']})" class="btn btn-outline btn-info">编辑</a>
                                    <a href="javascript:;" onclick="del({$val['id']},this)" class="btn btn-outline btn-danger">删除</a>
                                </td>
                            </tr>
                            {/foreach}
                            </tbody>
                        </table>
                        <div style="text-align: center;width: 100%;">
                            {$page}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{block name="javascript"}
<script src="ADMIN_JS/plugins/peity/jquery.peity.min.js"></script>
<script src="ADMIN_JS/content.min.js?v=1.0.0"></script>
<script src="ADMIN_JS/plugins/iCheck/icheck.min.js"></script>
<script src="ADMIN_JS/demo/peity-demo.min.js"></script>
<script>
    //$(document).ready(function(){$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",})});
    function edit(ids)
    {
        if(ids!=''){
            var url = '{:url("announcement/edit")}?id='+ids;
            url = url.replace('ids',ids);
        }else{
            var url = '{:url("announcement/add")}';
        }
        //自定页
        layer.open({
            type: 2,
            skin: 'layui-layer-demo', //样式类名
            area: ['60%', '80%'], //宽高
            shadeClose: true, //开启遮罩关闭
            content: url
        });
    }
    function del(id,obj) {
        var box = layer.confirm("您确定要删除吗？",function(){
            var url = '{:url("announcement/del")}';
            $.ajax({
                type:'post',
                url:url,
                data:{id:id},
                success:function(data){
                    if(data.code==1){
                        $(obj).parents("tr").remove();
                        layer.msg(data.message,{icon:6,time:1500});
                    }else{
                        layer.msg(data.message,{icon:5,time:1500});
                    }
                }
            })
        });
    }
    function lookInfo(id)
    {
        var url = '{:url("goods/lookSynopsis",["id"=>"goodsId"])}';
        url = url.replace('goodsId',id);
        layer.open({
            type: 2,
            skin: 'layui-layer-demo', //样式类名
            area: ['30%', '50%'], //宽高
            shadeClose: true, //开启遮罩关闭
            content: url
        });
    }
</script>
<script>
    function yanzheng(e,checks)
    {
        var checkboxs=document.getElementsByName(checks);
        for(i=0;i<checkboxs.length;i++)
        {
            checkboxs[i].checked=e.checked;
        }
    }
    function DelAll(){
        var id = new Array();
        var ids = $('[name="checkbox[]"]:checked');
        if(ids.length==0){
            layer.msg('请选择要删除的公告',{icon:2});
            return;
        }
        else{
            ids.each(function(){
                id.push($(this).val());//将选中的值添加到数组chk_value中
            })
        }
        var box = layer.confirm("您确定要删除吗？",function(){
            var loading = layer.msg('正在提交数据，请稍后...', {icon: 16,time:6000});
            $.post('{:url("announcement/dell")}',{id:id.join(',')},function(data){
                layer.close(loading);
                if(data.code=='1'){
                    layer.msg(data.message,{icon:1,time:2000});
                    setTimeout(function(){location.reload();},1500)
                }else{
                    layer.msg(data.message,{icon:2,time:2000});
                }
            });
        });
    }
</script>
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
{/block}